package com.calvin.springcloud.base;

import java.io.Serializable;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor // 生成全参数构造函数
@NoArgsConstructor // 生成无参构造函数
public class ResponseResult<T> implements Serializable {

	private static final long serialVersionUID = 4207958059471565866L;

	private boolean repCode;
	private String repMsg;
	private T repData;

	public ResponseResult(boolean repCode, String repMsg) {
		this(repCode, repMsg, null);
	}

	public ResponseResult(T repData) {
		this(true, "", repData);
	}
	

	public ResponseResult<T> success() {
		ResponseResult<T> res = new ResponseResult<T>();
		res.setRepCode(true);
		return res;
	}
	
	public ResponseResult<T> success(String resMsg) {
		ResponseResult<T> res = success();
		res.setRepMsg(resMsg);
		return res;
	}

	public ResponseResult<T> success(T repData) {
		ResponseResult<T> res = success();
		res.setRepData(repData);
		return res;
	}

	public ResponseResult<T> success(T repData, String repMsg) {
		ResponseResult<T> res = success();
		res.setRepMsg(repMsg);
		res.setRepData(repData);
		return res;
	}

	public ResponseResult<T> fail() {
		ResponseResult<T> res = new ResponseResult<T>();
		res.setRepCode(false);
		return res;
	}

	public ResponseResult<T> fail(String repMsg) {
		ResponseResult<T> res = fail();
		res.setRepMsg(repMsg);
		return res;
	}
}
